package com.demo.helloworld.web;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo.helloworld.bo.Sex;
import com.demo.helloworld.logic.SayHelloLogic;
import com.outstanding.framework.core.PendingException;
import com.outstanding.framework.plugin.springmvc.WebLogger;

@Controller
@RequestMapping("/demo")
public class DemoController {

	@Autowired
	private SayHelloLogic logic;

	@RequestMapping(value = "/say.do", method = RequestMethod.POST, produces = MediaType.ALL_VALUE)
	public @ResponseBody void say(@RequestBody DemoRequestDTO dto) throws PendingException {

		WebLogger.debug("调用say:" + dto.getSex().toString());
		this.logic.say();

	}

	@RequestMapping(value = "/sex.do", method = RequestMethod.POST, produces = MediaType.ALL_VALUE)
	public @ResponseBody DemoRequestDTO sex(@RequestBody DemoRequestDTO dto) throws PendingException {
		if (dto.getSex() != null) {
			WebLogger.debug("调用say:" + dto.getSex().toString());
		}
		DemoRequestDTO result = new DemoRequestDTO();
		result.setName("返回");
		result.setSex(dto.getSex());
		return result;

	}

	@RequestMapping(value = "/say1.do", method = RequestMethod.GET, produces = MediaType.ALL_VALUE)
	public @ResponseBody Sex say1(String userid,HttpSession session) throws PendingException {

		WebLogger.debug("调用say1:");
		return Sex.Man;

	}

}
